﻿using System;
using System.Text;

namespace ConsoleApplication1
{
    class XMLNodeVisitor
    {
        public string Visit(MyNode node)
        {
            var sb = new StringBuilder();
            sb.AppendLine(@"<?xml version=""1.0"" encoding=""utf-8""?>");
            sb.Append(node.Accept(this));
            return sb.ToString();
        }
        public string VisitNode(MyNode node)
        {
            var sb = new StringBuilder();
            sb.Append(string.Format("<{0}>", node.Name));
            foreach (var child in node.Childs)
            {
                sb.Append(child.Accept(this));
            }
            sb.Append(string.Format("</{0}>", node.Name));
            return sb.ToString();
        }
        public string VisitLeaf(Leaf leaf)
        {
            return String.Format("<{0}>{1}</{0}>", leaf.Name, leaf.Value);
        }
    }
}